package Day2025_04_09;

import java.util.Scanner;

public class Demo03 {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] hash = new int[100001];
        int nn = 0;
        for (int i = 0; i < n; i++) {
            int ret = sc.nextInt();
            hash[ret] += ret;
            nn = Math.max(ret, nn);
        }
        int[] dp1 = new int[nn + 1]; // 删
        int[] dp2 = new int[nn + 1]; // 不删
        int ret = 0;
        for (int i = 1; i <= nn; i++) {
            dp1[i] = dp2[i - 1] + hash[i];
            dp2[i] = Math.max(dp1[i - 1], dp2[i - 1]);
            ret = Math.max(ret, dp1[i]);
            ret = Math.max(ret, dp2[i]);
        }
        System.out.println(ret);
    }
}
